#ifndef TEXTQUERY_H
#define TEXTQUERY_H

#include "QueryResult.h"
#include <fstream>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

/* this version of the query classes includes two
 * members not covered in the book:  
 *   cleanup_str: which removes punctuation and 
 *                converst all text to lowercase
 *   display_map: a debugging routine that will print the contents
 *                of the lookup mape
*/

class QueryResult;// declaration needed for return type in the query function
class TextQuery
{
public:
#ifdef TYPE_ALIAS_DECLS
    using line_no = std::vector<std::string>::size_type;
#else
    typedef std::vector<std::string>::size_type line_no;
#endif
    explicit TextQuery(std::ifstream &);
    QueryResult query(const std::string &) const;
    void        display_map();// debugging aid: print the map

private:
    // canonicalizes text: removes punctuation and makes everything lower case
    static std::string cleanup_str(const std::string &);

private:
    std::shared_ptr<std::vector<std::string>>                 file;// input file
    // maps each word to the set of the lines in which that word appears
    std::map<std::string, std::shared_ptr<std::set<line_no>>> wm;
};
#endif
